package com.heima.juc.n4;

import com.heima.juc.n2.Sleeper;
import lombok.extern.slf4j.Slf4j;

/**
 * @author : leimingchao
 * @date Date : 2022年02月11日 21:20
 */
@Slf4j(topic = "c.TestLiveLock")
public class TestLiveLock {

    static volatile int count = 10;

    static final Object lock = new Object();

    public static void main(String[] args) {

        new Thread(() -> {
            //期望减到0退出循环
            while (count > 0) {
                Sleeper.sleep(0.2);
                count--;
                log.debug("count:{}",count);
            }
        },"t1").start();

        new Thread(() -> {
            //期望减到20退出循环
            while (count < 20) {
                Sleeper.sleep(0.2);
                count++;
                log.debug("count:{}",count);
            }
        },"t2").start();
    }
}
